package dev.ece.suit.loader.models.fbx;

import java.io.IOException;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import dev.ece.util.lib.Matrix4f;

public class FBXPoseNode {

	public static final String POSE_NODE = "PoseNode";
	
	public static final String NODE = "Node";
	
	public static final String MATRIX = "Matrix";
	
	private long id;
	
	private Matrix4f matrix;
	
	private FBXPose pose;
	
	public static FBXPoseNode[] parseFBXPoseNode(FBXElement[] elements, FBXPose pose) throws IOException {
		FBXPoseNode[] poseNodes = null;
		if(elements != null && elements.length > 0) {
			poseNodes = new FBXPoseNode[elements.length];
			FBXElement element = null;
			for(int i=0; i<poseNodes.length; i++) {
				element = elements[i];
				poseNodes[i] = new FBXPoseNode();
				poseNodes[i].id = (Long) element.findFirstChild(NODE).getProperties()[0].getValue();
				poseNodes[i].matrix = element.findFirstChild(MATRIX).getProperties()[0].toMatrix4f();
				poseNodes[i].pose = pose;
			}
		}
		return poseNodes;
	}

	public long getId() {
		return id;
	}

	public Matrix4f getMatrix() {
		return matrix;
	}

	public FBXPose getPose() {
		return pose;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(id).toHashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null) {
			return false;
		}
		if(!(obj instanceof FBXPoseNode)) {
			return false;
		}
		FBXPoseNode node = (FBXPoseNode) obj;
		return new EqualsBuilder()
				.append(this.id, node.id)
				.isEquals();
	}

}
